<template>
	<view>
		<uni-segmented-control :current="current" :values="items.map(item=>item.title)" @clickItem="onClickItem" style-type="text" active-color="#4cd964"
		 class="video_wrap"></uni-segmented-control>
		<view class="content">
			<view v-if="current === 0">
				<video-recommend :category="category" @scrollbot="showmore"></video-recommend>
			</view>
			<view v-if="current === 1">
				<video-recommend :category="category" @scrollbot="showmore"></video-recommend>
			</view>
			<view v-if="current === 2">
				<video-recommend :category="category" @scrollbot="showmore"></video-recommend>
			</view>
			<view v-if="current === 3">
				<video-recommend :category="category" @scrollbot="showmore"></video-recommend>
			</view>
			<view v-if="current === 4">
				<video-category></video-category>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		uniBadge,
		uniSegmentedControl
	} from '@dcloudio/uni-ui'
	import videoCategory from './video-category/index'
	import videoRecommend from './video-recommend/index'

	export default {
		data() {
			return {
				items: [{
						title: "推荐",
						url: 'http://157.122.54.189:9088/videoimg/v1/videowp/featured?limit=30&order=hot&skip=0',
						params: {
							limit: 30,
							skip: 0,
							order: 'hot'
						}
					},
					{
						title: "娱乐",
						url: 'http://157.122.54.189:9088/videoimg/v1/videowp/category/59b25abbe7bce76bc834198a?limit=30&order=new&skip=0',
						params: {
							limit: 30,
							skip: 0,
							order: 'new'
						}
					},
					{
						title: "最新",
						url: 'http://157.122.54.189:9088/videoimg/v1/videowp/videowp?limit=30&order=new&skip=0',
						params: {
							limit: 30,
							skip: 0,
							order: 'new'
						}
					},
					{
						title: "热门",
						url: 'http://157.122.54.189:9088/videoimg/v1/videowp/videowp?limit=30&order=hot&skip=0',
						params: {
							limit: 30,
							skip: 0,
							order: 'hot'
						}
						
					},
					{
						title:"分类",
						params: {
							limit: 30,
							skip: 0,
							order: 'new'
						}
					}
				],
				current: 0,
				hasmore: true,
				category: []
			}
		},
		methods: {
			onClickItem(e) {
				if (this.current !== e.currentIndex) {
					this.current = e.currentIndex;
				}
				if(this.current != this.items.length - 1){
					this.items.forEach(item=>{
						item.params.limit = 30,
						item.params.skip = 0
					})
					this.category = [];
					this.getList()
				}
				
			},
			async getList() {
				let info = await this.request({
					url: this.items[this.current].url,
					data: this.items[this.current].params
				})
				
				if (info.data.res.videowp.length === 0) {
					this.hasmore = false
				} else {
					this.category = [...this.category, ...info.data.res.videowp]
					
				}
				},
				//显示更多数据
				showmore(){
					if(this.hasmore){
						this.items[this.current].params.skip+=this.items[this.current].params.limit
						this.getList()
					}else{
						wx.showToast({
							title:"没有更多数据了",
							icon:"none"
						})
					}
				}
			},

			onLoad() {
				wx.setNavigationBarTitle({
					title: "精美视频"
				})
				this.getList()
				

			},
			components: {
				uniBadge,
				uniSegmentedControl,
				videoCategory,
				videoRecommend
			}


	
	}
</script>

<style lang="scss">

</style>
